package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.MaterialMapEntity;
import com.swgk.core.dialog.BaseBottomDialog;
import com.swgk.core.dialog.DialogViewHolder;

public class MaterialMapDialog extends BaseBottomDialog {

    private MaterialMapEntity materialMapEntity;
    private TextView titleView;
    private TextView tv_address;
    private TextView tv_districtName;
    private TextView tv_main;
    private TextView tv_look;
    private TextView tv_km;
    private ImageView img_close;
    private DialogClickCallBack dialogClickCallBack;

    public MaterialMapDialog(Context context, DialogCallBack dialogCallBack) {
        super(context, dialogCallBack);
    }

    public MaterialMapDialog(Context context, int theme, DialogCallBack dialogCallBack) {
        super(context, theme, dialogCallBack);
    }

    @Override
    protected int dialogLayout() {
        return R.layout.dialog_map_window;
    }

    @Override
    protected void initView(DialogViewHolder holder, Bundle savedInstanceState) {
        titleView = holder.getDialog().findViewById(R.id.title_view);
        tv_address = holder.getDialog().findViewById(R.id.tv_address);
        tv_districtName = holder.getDialog().findViewById(R.id.tv_districtName);
        tv_main = holder.getDialog().findViewById(R.id.tv_main);
        tv_look = holder.getDialog().findViewById(R.id.tv_look);
        tv_km = holder.getDialog().findViewById(R.id.tv_km);
        img_close = holder.getDialog().findViewById(R.id.img_close);
        tv_look.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialogClickCallBack == null) {
                    return;
                }
                if (materialMapEntity == null) {
                    return;
                }
                dialogClickCallBack.onClickShop(materialMapEntity.getCompanyId()+"");
            }
        });
        img_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (dialogClickCallBack == null) {
                    return;
                }
                dialogClickCallBack.dissMiss();
            }
        });
    }

    public MaterialMapEntity getData() {
        return materialMapEntity;
    }

    public MaterialMapDialog setData(MaterialMapEntity materialMapEntity) {
        this.materialMapEntity = materialMapEntity;
        titleView.setText(materialMapEntity.getName());
        tv_address.setText(materialMapEntity.getAddress());
        tv_main.setText(materialMapEntity.getMainBusiness());
        tv_km.setText(materialMapEntity.getDistance());
        tv_districtName.setText(materialMapEntity.getSettlingTime());
        return this;
    }

    public interface DialogClickCallBack {
        void onClickShop(String shopId);
        void dissMiss();
    }

    public MaterialMapDialog setDialogClickCallBack(DialogClickCallBack dialogClickCallBack) {
        this.dialogClickCallBack = dialogClickCallBack;
        return this;
    }
}
